/**
 * WordObject.java 
 * 
 * Klasa przedstawiajaca model obiektu slowa. Zawiera wlasciwe slowko + licznik.
 * Dodatkowo z powodu istnienia kolizji w tablicach haszujacych tworzone sa listy jednokierunkowe.
 * Klasa ta posiada wiec wskaznik na nastepny element (next).
 *
 * @author Mateusz Grzechociński
 *		   mateusz@grzechocinski.net
 *
 * @date 2006-12-16, 21:31:57
 */
package net.grzechocinski.wordcounter.KMP;

import java.io.Serializable;

public class WordObject implements Serializable{
	
	private String word;
	private int alone_counter;
	private int inOther_counter;

	public WordObject(String word){
		this.alone_counter = 1;
		this.word = word;				
	}

	public WordObject(String word, int alone_counter, int inOther_counter) {
		this.word = word;
		this.alone_counter = alone_counter;
		this.inOther_counter = inOther_counter;
	}

	public void setWord(String word){
		this.word = word;
	}

	public String getWord(){
		return word;
	}
	
	public void setAloneCounter(int alone_Counter){
		this.alone_counter = alone_Counter;
	}

	public int getAloneCounter(){
		return alone_counter;
	}
	
	public void incrementAloneCounter(){
		alone_counter++;
	}
	
	public void setInOtherCounter(int inOther_Counter){
		this.inOther_counter = inOther_Counter;
	}

	public int getInOtherCounter(){
		return inOther_counter;
	}
	
	public void incrementInOtherCounter(){
		inOther_counter++;
	}

	public int getAllOccuresCounter(){
		return alone_counter + inOther_counter;
	}
	
	public int getSortKey(int sortBy){
		if(sortBy == 1)
			return alone_counter;				
		if(sortBy == 2)
			return inOther_counter;
		else		
			return alone_counter + inOther_counter;
	}

	@Override
	public String toString() {
		return "WordObject{" +
				"word='" + word + '\'' +
				", alone_counter=" + alone_counter +
				", inOther_counter=" + inOther_counter + "}\n";
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (!(o instanceof WordObject)) return false;

		WordObject that = (WordObject) o;

		if (alone_counter != that.alone_counter) return false;
		if (inOther_counter != that.inOther_counter) return false;
		if (word != null ? !word.equals(that.word) : that.word != null) return false;

		return true;
	}

	@Override
	public int hashCode() {
		int result = word != null ? word.hashCode() : 0;
		result = 31 * result + alone_counter;
		result = 31 * result + inOther_counter;
		return result;
	}
}
